import { TrayIcon } from '@tauri-apps/api/tray';
import { Menu } from '@tauri-apps/api/menu';
import { defaultWindowIcon } from '@tauri-apps/api/app';
import { getCurrentWebview } from '@tauri-apps/api/webview';
import { invoke } from '@tauri-apps/api/core'

(async () => {

  const appWindow = getCurrentWebview().window;

  const menu = await Menu.new({
    items: [
      {
        id: 'show',
        text: '显示',
        action: () => {
          appWindow.show();
          console.log('显示');
        },
      },
      {
        id: 'hide',
        text: '隐藏',
        action: () => {
          appWindow.hide()
          console.log('隐藏');
        },
      },
      {
        id: 'quit',
        text: '退出',
        action: () => {
          invoke('quit_app')
          appWindow.close()
          console.log('退出');
        },
      },
    ],
  });

  const options = {
    id:"menu1",
    menu,
    icon: (await defaultWindowIcon())!,
    //   menuOnLeftClick: true,
  };

  const tray = await TrayIcon.new(options);
  console.log("%c Line:37 🍖 tray", "color:#b03734", tray);


})()